package com.itheima.d13_stringBuilder;

public class Test1 {
    public static void main(String[] args) {
        // 目标：搞清楚StringBuilder的用法和作用。
        StringBuilder sb = new StringBuilder(); // ""
        System.out.println("sb = " + sb);

        StringBuilder sb2 = new StringBuilder("Hello");
        System.out.println("sb2 = " + sb2);//Hello

        // 1、拼接内容
        sb2.append(100);
        sb2.append(true);
        sb2.append("World");
        System.out.println("sb2 = " + sb2);

        // 支持链式编程
        sb2.append("Java").append("C++").append("Python");
        System.out.println("sb2 = " + sb2);

        // 2、反转操作(reverse() )
        sb2.reverse();
        System.out.println("sb2 = " + sb2);

        // 3、返回字符串的长度(length() )
        int len = sb2.length();
        System.out.println("len = " + len);

        // 4、把StringBuilder对象又转换成String类型。
        String str = sb2.toString();
        System.out.println("str = " + str);
    }
}
